<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" 
%><%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" 
%><%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" 
%><%@ page contentType="text/html;charset=ISO-8859-1"
%><html:html locale="true">
    <head>
        <title><bean:message key="requisitos.title"/></title>
        <html:base/>
        <script type="text/javascript" src="../js/prototype.js"></script>
        <script type="text/javascript" src="../js/funciones.js"></script>
        <script type="text/javascript">            
            function prioridad(){
                //document.getElementById("prioridad").selectedIndex = ${prioridad};
            }
            
            function formatearRequisitos(){
                var i = 0;
                var j=0;
                var requisitos;
                requisitos = $('30801').value.split(";");
                if(requisitos[0] != "false"){
                    var a = "";
                    asigs = requisitos[0].split(",");
                    while($("asignatura"+i)){
                        for(j=0;j<asigs.length;j++){
                            if(asigs[j] == $("asignatura"+i).value)
                                $("asignatura"+i).checked = true;
                        }
                        i++;
                    }
                }

                if(requisitos[1] != "false")
                    $('pera').selectedIndex = requisitos[1];


                if(requisitos[2] == "true")
                    $('percs').checked = true;
                else
                    $('percn').checked = true;

                if(requisitos[3] != "false")
                    $('num').value = requisitos[3];
                else
                    $('num').innerHTML = requisitos[3];

                if(requisitos[4] == "true")
                    $('ress').checked = true;
                else
                    $('resn').checked = true;

            }
            
            /*
             * Estas funcion toma los valores seleccionados
             * en el formulario de la vista y los concatena en
             * el string que se guarda en la bd
             */
            function armarStringRequisito(){
                var i = 0;
                var j = 0;
                var marcados = false;
                var requisitos;
                
                var a = "";
                while($("asignatura"+j)){
                        if($("asignatura"+j).checked){
                            a += $("asignatura"+j).value+",";
                            marcados = true;
                        }
                    j++;
                }
                if(marcados)
                    requisitos = a.substring(0,a.length-1);
                else
                    requisitos = "false";

                if($('pera').selectedIndex > 0)
                    requisitos += ";" + $('pera').value;
                else
                    requisitos += ";" + "false";
                
                requisitos += ";" + $('percs').checked;
                
                
                
                if($('num').value != "" & $('num').value != 0)
                    requisitos += ";" + $('num').value;
                else
                    requisitos += ";" + "false";

                requisitos += ";" + $('ress').checked;

                $('30801').value = requisitos;
            }
        </script>
        <link rel="stylesheet" type="text/css" href="../css/style.css"></link>
<style type="text/css">
div#box30799 {width: 400px; margin: 40px auto; }
form#30799 {float: left; margin: 0; padding: 0; display: inline; width: 400px; }
form#30799 p {float: left; margin: 0; padding: 0; display: inline; }
form#30799 label {float: left; margin: 0; padding: 0; display: inline; overflow: hidden; }
form#30799 input {float: left; margin: 0; padding: 0; display: inline; }
  form#30799 p#30803_C {clear: both; width: 400px; }
  form#30799 p#30803_C label {clear: both; width: 400px; }
  form#30799 p#30803_C input {clear: both; width: 396px; }
  form#30799 p#30802_C {clear: both; width: 400px; }
  form#30799 p#30802_C label {clear: both; width: 400px; }
  form#30799 p#30802_C input {clear: both; width: 396px; }
  form#30799 p#30805_C {clear: both; width: 400px; }
  form#30799 p#30805_C label {clear: both; width: 400px; }
  form#30799 p#30805_C input {clear: both; width: 396px; }
  form#30799 p#30801_C {clear: both; width: 400px; }
  form#30799 p#30801_C label {clear: both; width: 400px; }
  form#30799 p#30801_C input {clear: both; width: 396px; }
  form#30799 p#30804_C {clear: both; width: 400px; }
  form#30799 p#30804_C label {clear: both; width: 400px; }
  form#30799 p#30804_C input {clear: both; width: 396px; }
  form#30799 p#30800_C {clear: both; width: 400px; }
  form#30799 p#30800_C label {clear: both; width: 400px; }
  form#30799 p#30800_C input {clear: both; width: 396px; }

</style>
    </head>
    <body onload="formatearRequisitos()">
        <div id="header">
            <div id="title"><bean:message key="requisitos.title"/></div>
            <div id="menu">
                <ul id="nav">
                    <li><html:link action="/RequisitosElim.do" paramId="idRequisito" paramName="idRequisito"><bean:message key="requisitos.label1"/></html:link></li>
                    <li>&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;</li>
                    <li><html:link action="/RequisitosGrupoCrearI.do" paramId="idGrupo" paramName="idGrupo"><bean:message key="requisitos.label2"/></html:link></li>
                    <li>&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;</li>
                    <li><html:link action="/GrupoI.do" paramId="idGrupo" paramName="idGrupo"><bean:message key="requisitos.label3"/></html:link></li>

                </ul>
            </div>
        </div>
        <div id="body_wrapper">
            <div id="body">
                <div id="split">
                    <div class="top"></div>
                    <div id="left">
                        <div class="content">
                            ${empty msg ? "" : msg}
                <div class="box30799"><html:form styleId="F30799" action="/RequisitosAct.do">
                  <html:hidden property="idRequisito"/>
                  <p id="30802_C"><label for="30802"><bean:message key="FRequisitos.label1"/> &nbsp; </label><html:select styleId="30802" property="asignatura"><html:optionsCollection property="listAsignatura"/></html:select></p>
                  <p id="30801_C"><html:hidden styleId="30801" property="requisitos"/></p>
                  <html:hidden styleId="30804" property="grupo"/>
                <% request.setAttribute("_vacio", new Object[0]); int c = 0; %>
                <table border="1"><tbody>
                    <tr>
                        <th>Requisitos</th>
                        <th>Per&iacute;odo aprobado</th>
                        <th>Permiso coordinaci&oacute;n</th>
                        <th>Cr&eacute;ditos aprobados</th>
                        <th>Reserva</th>
                    </tr>
                        <tr>
                            <td align="center">
                                <table align="center" onclick="armarStringRequisito();">
                                    <tbody>
                      <logic:iterate id="asignatura" collection="${empty L_Asignatura ? _vacio : L_Asignatura}">
                                    <tr><td><input type="checkbox" value="${asignatura.codigo}" id="asignatura<%=c++%>">${asignatura.codigo}</td></tr>
                      </logic:iterate>
                                    </tbody>
                                </table>
                            </td>
                            <td align="center">
                                <select name="pera" id="pera" onchange="armarStringRequisito();">
                                    <option value="false">Seleccione
                                    <option value="1">1
                                    <option value="2">2
                                    <option value="3">3
                                    <option value="4">4
                                    <option value="5">5
                                    <option value="6">6
                                    <option value="7">7
                                    <option value="8">8
                                    <option value="9">9
                                    <option value="10">10
                                    <option value="11">11
                                    <option value="12">12
                                    <option value="13">13
                                    <option value="14">14
                                    <option value="15">15  
                                </select>
                            </td>
                            <td align="center" onclick="armarStringRequisito();">
                                <input type="radio" name="perc" value="true" id="percs" >Si &nbsp;<br>
                                <input type="radio" name="perc" value="false" id="percn" >No
                            </td>
                            <td align="center">
                                <input type="text" id="num" size="3" onKeyPress="return acceptNum(event);" onkeyup="armarStringRequisito();">
                            </td>
                            <td align="center" onclick="armarStringRequisito();">
                                <input type="radio" name="res" value="true" id="ress" >Si &nbsp;<br>
                                <input type="radio" name="res" value="false" id="resn" >No
                            </td>
                        </tr>
                  </tbody>
                  </table>
                  <br>
                  <html:submit styleClass="button"><bean:message key="requisitos.label0"/></html:submit>
                </html:form></div>

                        </div>
                    </div>
                    <div id="right"><jsp:include page="/ppal/menu.jsp" flush="true"/></div>
                    <div class="clearer"></div>
                    <div class="bottom"></div>
                </div>
                <div class="clearer"></div>
            </div>
            <div class="clearer"></div>
        </div>
        <div id="end_body"></div>
        <h3 class="title"></h3>
        <div id="footer"> <bean:message key="bottom.label"/> </div>
        
    </body>
</html:html>